<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<#include "../commons/imports.html"/>
</head>
<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">
		<#include "../commons/header.html"/> <#include
		"../commons/sider.html"/>
		<div class="layui-body">
			<blockquote class="layui-elem-quote">
				<div class="layui-inline">
					<div class="layui-input-inline">
						<input type="text" value="" placeholder="请输入角色名称"
							class="layui-input search_input layui-btn-disabled">
					</div>
					<a class="layui-btn search_btn layui-btn-disabled">
					<i class="layui-icon">&#xe615;</i>查询</a>
				</div>
				<div class="layui-inline">
					<div class="layui-btn-group">
						<button class="layui-btn layui-btn-sm layui-btn-disabled">
							<i class="layui-icon"></i>增加
						</button>
						<button class="layui-btn layui-btn-sm layui-btn-disabled">
							<i class="layui-icon"></i>编辑
						</button>
						<button class="layui-btn layui-btn-sm layui-btn-disabled">
							<i class="layui-icon"></i>删除
						</button>
					</div>
				</div>
			</blockquote>
			<div style="padding: 5px;">
				<table class="layui-table">
					<colgroup>
						<col width="150">
						<col width="200">
						<col width="300">
						<col width="100">
					</colgroup>
					<thead>
						<tr>
							<th>编码</th>
							<th>名称</th>
							<th>持有资源</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<#list roles as role>
						<tr>
							<td>${role.code!}</td>
							<td>${role.name!}</td>
							<th>${role.resourceNames!}</th>
							<td>
								<a class="layui-btn layui-btn-mini" onclick="allotResource('${role.code!}');">
								<i class="layui-icon">&#xe642;</i> 分配资源</a>
							</td>
						</tr>
						</#list>
					</tbody>
				</table>
			</div>

			<!-- 内容主体区域 -->

		</div>
		<#include "../commons/footer.html"/>
	</div>
	<script type="text/javascript" src="${ctx}/assets/js/main.js"></script>
		<script>
		function allotResource(_roleId) {
			ajaxPost("${ctx}/role/allot_resource",{
				roleId:_roleId
			},function(result) {
				layer.open({
					type:1,
					title : '分配资源',
					area : [ '700px', '450px' ],
					skin : 'layui-layer-lan',
					btn : '关闭',
					content : result
				});
			});
		}
		function saveAllotResource(_roleId) {
			
			var _resourceIdArray = [];
			$("#allot-resource-form option:selected").each(function(){
				_resourceIdArray.push($(this).val());
	        });
			var _resourceIds = _resourceIdArray.join(',');
			var _roleId = $("#roleId").val();

			ajaxPost("${ctx}/role/save_role_resource",{
				roleId:_roleId
				,resourceIds:_resourceIds
			},function(result) {
				layer.closeAll();
				layer.alert('资源分配成功',{icon:1, title:'成功'});
				window.location.href = '${ctx}/role/list';
			});
		}
	</script>
</body>
</html>